from dingxiang_doctor.settings import SECRET_KEY
import jwt

class MyJWT:
    def __init__(self):
        self.secret_key = SECRET_KEY

    def jwt_encode(self, data):
        return jwt.encode(data, self.secret_key, algorithm='HS256')

    def jwt_decode(self, token):
        return jwt.decode(token, self.secret_key, algorithms='HS256')

    # 通过在重写new方法，在new魔法方法中判断来获取单例模式
    # _instance = None
    # def __new__(cls, *args, **kwargs):
    #     if cls._instance is None:
    #         cls._instance = super().__new__(cls)
    #     return cls._instance

# 与import搭配使用可以形成单例模式
myjwt = MyJWT()
